<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->integerIncrements('id');
            $table->string('spreadid',50)->default('')->unique()->nullable(false)->comment('用户推广ID');
            $table->string('email',50)->default('')->unique()->nullable(false)->comment('用户邮箱（账号）');
            $table->string('avator')->default('')->nullable(false)->comment('用户头像');
            $table->string('username',100)->default('')->nullable(false)->comment('用户英文名称');
            $table->string('username_zn',100)->default('')->nullable(false)->comment('用户中文名称');
            $table->string('contact',50)->default('')->nullable(false)->comment('用户电话');
            $table->string('password')->nullable(false)->default('')->comment('用户密码');
            $table->string('paypass',100)->default('')->nullable(false)->comment('支付密码');
            $table->unsignedInteger('balance')->default(0)->nullable(false)->comment('钱包金额,单位为分');
            $table->unsignedInteger('cycle_balance')->default(0)->nullable(false)->comment('反馈钱包金额,单位为分');
            $table->unsignedInteger('coin')->default(0)->nullable(false)->comment('钱包积分');
            $table->unsignedInteger('total')->default(0)->nullable(false)->comment('累计消费总金额');
            $table->date('birthday')->comment('生日');
            $table->text('token')->nullable(false)->comment('用户token');
            $table->softDeletes();
            $table->timestamps();
            $table->engine = 'InnoDB';
        });
        DB::statement("alter table `users` comment '用户表' ");

        Schema::create('user_levels', function (Blueprint $table) {
            $table->integerIncrements('id');
            $table->string('levelname')->nullable(false)->default('')->comment('等级英文名');
            $table->string('levelname_zn')->nullable(false)->default('')->comment('等级中文名');
            $table->bigInteger('min')->default(0)->nullable(false)->comment('等级最低累计消费额度');
            $table->bigInteger('max')->default(0)->nullable(false)->comment('等级最高累计消费额度');
            $table->tinyInteger('cycle_rate')->default(0)->nullable(false)->comment('回馈钱包返现比例');
            $table->tinyInteger('integral')->default(0)->nullable(false)->comment('积分返赠比例');
            $table->tinyInteger('spred_rate')->default(0)->nullable(false)->comment('推荐返佣比例');
            $table->timestamps();
        });
        DB::statement("alter table `user_levels` comment '用户等级信息表' ");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('user_levels');
    }
}
